/* 
 * Copyright [2018] [Alex/libo(liboms@hotmail.com)]
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.hyts.guava.math;

import com.google.common.math.IntMath;
import com.google.common.math.LongMath;

/** 
 * @title Maths.java  
 * @package com.hyts.guava.math  
 * @description  Guava Math数学处理方法方式类<br>
 * 				•Guava Math 针对各种不常见的溢出情况都有充分的测试；对溢出语义，Guava 文档也有相应的说明；如<br>
				     果运算的溢出检查不能通过，将导致快速失败；<br>
				• Guava Math 的性能经过了精心的设计和调优；虽然性能不可避免地依据具体硬件细节而有所差异，但 Gua<br>
				  va Math 的速度通常可以与 Apache Commons 的 MathUtils 相比，在某些场景下甚至还有显著提升；<br>
				• Guava Math 在设计上考虑了可读性和正确的编程习惯；IntMath.log2(x, CEILING) 所表达的含义，即使<br>
				     在快速阅读时也是清晰明确的。而 32-Integer.numberOfLeadingZeros(x – 1)对于阅读者来说则不够清<br>
				      晰。		 <br>
				    注意：Guava Math 和 GWT 格外不兼容，这是因为 Java 和 Java Script 语言的运算溢出逻辑不一样。  
 * @see TODO
 * @author libo/Alex
 * @email liboms@hotmail.com/liboware@163.com  
 * @date 2018年5月19日 
 * @version V1.0 
 */
public final class Maths {
	
	/**
	 * @Title: addition
	 * @Description: 两个数值进行相加
	 * @param param1
	 * @param param2
	 * @return
	 * @return: Integer
	 */
	public static <T> Object addition(T param1,T param2){ 
		if((param1.getClass() != param2.getClass()))
			throw new RuntimeException("传入的参数必须类型保持一致!");
		if(param1 instanceof Integer)
			return IntMath.checkedAdd((Integer)param1, (Integer)param2);
		if(param2 instanceof Long)
			return LongMath.checkedAdd((Long)param1, (Long)param2);
		return null;
	}
	

	/**
	 * @Title: substraction
	 * @Description: 两个数值进行相减
	 * @param param1
	 * @param param2
	 * @return
	 * @return: Object
	 */
	public static <T> Object substraction(T param1,T param2){ 
		if((param1.getClass() != param2.getClass()))
			throw new RuntimeException("传入的参数必须类型保持一致!");
		if(param1 instanceof Integer)
			return IntMath.checkedSubtract((Integer)param1, (Integer)param2);
		if(param2 instanceof Long)
			return LongMath.checkedSubtract((Long)param1, (Long)param2);
		return null;
	}
	
	
}
